var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2DataManager = require("DataManager");
var $2JoyStick1 = require("JoyStick1");
var $2UIManager = require("UIManager");
var $2EventsMgr = require("EventsMgr");
var $2BgCtrl = require("BgCtrl");
var $2AudioManager = require("AudioManager");
var $2KDefine = require("KDefine");
var $2UserDataManager = require("UserDataManager");
var $2Role1 = require("Role1");
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var y;
(function (e) {
  e[e.norm = 0] = "norm";
  e[e.tiao = 1] = "tiao";
  e[e.likai = 2] = "likai";
  e[e.tiao_end = 3] = "tiao_end";
})(y || (y = {}));
var def_DfbwzhUI = /* */function (_cc$Component15) {
  babel_inherits(C, _cc$Component15);
  var _super17 = babel_createSuper(C);
  function C() {
    var _this42;
    babel_classCallCheck(this, C);
    _this42 = _super17.apply(this, arguments);
    _this42.fuhuoView = null;
    _this42.endView = null;
    _this42.zidanNode = null;
    _this42.player = null;
    _this42.joyStick = null;
    _this42.speed = 500;
    _this42.bgs = null;
    _this42.fds = null;
    _this42.shangtiao = null;
    _this42.xiaza = null;
    _this42.sheji = null;
    _this42.degree = 0;
    _this42.sheji_num = 2;
    _this42.role_y = -165;
    _this42.role_x = -343;
    _this42.distance = null;
    _this42.huangdan1 = false;
    _this42.hp = null;
    _this42.startClickTime = 0;
    _this42.clickTime = 0;
    return _this42;
  }
  babel_createClass(C, [{
    key: "onLoad",
    value: function onLoad() {
      var _this43 = this;
      $2UIManager.default.instance.hideUI("MoneyPanelUI");
      this.player = cc.find("role1", this.node);
      this.joyStick = cc.find("JoyStick1", this.node);
      this.bgs = cc.find("bgs", this.node);
      this.fds = cc.find("fds", this.node);
      this.shangtiao = cc.find("Skills/shangtiao", this.node);
      this.xiaza = cc.find("Skills/xiaza", this.node);
      this.sheji = cc.find("Skills/sheji", this.node);
      this.distance = cc.find("distance", this.node);
      this.hp = cc.find("role1/hp", this.node);
      this.shangtiao.on(cc.Node.EventType.TOUCH_START, this.on_shangtiao, this);
      this.xiaza.on(cc.Node.EventType.TOUCH_START, this.on_xiaza, this);
      this.xiaza.on(cc.Node.EventType.TOUCH_END, this.on_xiaza_end, this);
      this.sheji.on(cc.Node.EventType.TOUCH_START, this.on_sheji, this);
      cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
      cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
      $2EventsMgr.EventsManager.on("play_sp", function (e) {
        if (_this43.player) {
          if (e) {
            _this43.player.getComponent(sp.Skeleton).setAnimation(0, "run1", true);
            _this43.player.getComponent(sp.Skeleton).setAnimation(1, "run2", true);
            $2DataManager.default.instance.is_running = true;
          } else {
            _this43.player.getComponent(sp.Skeleton).setAnimation(0, "daiji1", true);
            _this43.player.getComponent(sp.Skeleton).setAnimation(1, "1tui2", true);
            $2DataManager.default.instance.is_running = false;
          }
        }
      });
      $2EventsMgr.EventsManager.on("game_over", function () {
        _this43.game_over();
      });
      $2EventsMgr.EventsManager.on("restart", function () {
        _this43.restart();
      });
      $2EventsMgr.EventsManager.on("fuhuo", function () {
        _this43.fuhuo();
      });
      this.init();
      this.initPlatform();
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      $2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p8") && $2pvzChannel.pvzChannel.instance().pauseAdTimeCount();
    }
  }, {
    key: "init",
    value: function init() {
      if (this.bgs && this.player) {
        $2ADManager.default.instance.recorderStart();
        $2UserDataManager.default.instance.getBwzdaifuInfo();
        $2UserDataManager.default.instance.getBwzjsInfo();
        $2DataManager.default.instance.fd_num = 0;
        this.player.active = true;
        this.huangdan1 = false;
        $2DataManager.default.instance.is_running = false;
        $2DataManager.default.instance.is_over = false;
        this.player.getComponent($2Role1.default).flag = y.norm;
        this.player.scaleX = .3;
        this.bgs.getComponent($2BgCtrl.default).set_dir(-1);
        this.player.getComponent(sp.Skeleton).setAnimation(0, "daiji1", true);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "1tui2", true);
        this.player.setPosition(this.role_x, this.role_y);
        this.joyStick.getChildByName("StickBg1").setPosition(this.joyStick.getChildByName("Anchor").position);
        this.joyStick.getChildByName("StickBg1").getChildByName("Stick1").setPosition(cc.v2(0, 0));
        this.joyStick.getComponent($2JoyStick1.default).dir = cc.v2(0, 0);
        $2DataManager.default.instance.distance = 0;
        this.player.getComponent($2Role1.default).hp_total = this.player.getComponent($2Role1.default).hp_role = $2UserDataManager.default.instance.bwzdaifuInfo[0].value;
        this.hp.getComponent(cc.ProgressBar).progress = 1;
      }
    }
  }, {
    key: "fuhuo",
    value: function fuhuo() {
      var e = $2DataManager.default.instance.distance;
      this.restart();
      $2DataManager.default.instance.distance = e;
    }
  }, {
    key: "restart",
    value: function restart() {
      if (!this.bgs) {
        return;
      }
      this.init();
      var e = this.bgs.children.length;
      for (var _t16 = 0; _t16 < e; _t16++) {
        this.bgs.children[_t16].getChildByName("fds").removeAllChildren();
        this.bgs.children[_t16].getChildByName("jss").removeAllChildren();
      }
      this.bgs.getComponent($2BgCtrl.default).init();
    }
  }, {
    key: "onKeyUp",
    value: function onKeyUp(e) {
      if (!$2DataManager.default.instance.is_over) {
        this.player.getComponent(sp.Skeleton).setAnimation(0, "daiji1", true);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "1tui2", true);
        $2DataManager.default.instance.is_running = false;
      }
    }
  }, {
    key: "onKeyDown",
    value: function onKeyDown(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      switch (e.keyCode) {
        case cc.macro.KEY.a:
          this.bgs.getComponent($2BgCtrl.default).set_dir(1);
          this.player.scaleX = -.3;
          $2DataManager.default.instance.is_running = true;
          break;
        case cc.macro.KEY.d:
          this.bgs.getComponent($2BgCtrl.default).set_dir(-1);
          this.player.scaleX = .3;
          $2DataManager.default.instance.is_running = true;
      }
      var t = this.player.getComponent(sp.Skeleton).animation;
      if ("lunqiang1" != t && "huangdan1" != t && "sheji1" != t && "run1" !== t) {
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run1", true);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "run2", true);
      }
    }
  }, {
    key: "game_over",
    value: function game_over() {
      var _this44 = this;
      if (this.player) {
        this.player.getComponent(sp.Skeleton).setAnimation(0, "die", false);
        this.player.getComponent(sp.Skeleton).clearTrack(1);
        this.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
          "die" == e.animation.name && (_this44.player.active = false);
        });
        $2DataManager.default.instance.is_over = true;
        this.unscheduleAllCallbacks();
        $2AudioManager.default.instance.playEffect($2KDefine.AudioName.jieshu);
        this.scheduleOnce(function () {
          if ($2DataManager.default.instance.fuhuo_flag) {
            $2DataManager.default.instance.fuhuo_flag = false;
            _this44.endView.active = true;
          } else {
            _this44.fuhuoView.active = true;
          }
        }, 1);
      }
    }
  }, {
    key: "changedh",
    value: function changedh() {
      if ($2DataManager.default.instance.is_running) {
        this.player.getComponent(sp.Skeleton).setAnimation(0, "run1", true);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "run2", true);
      } else {
        this.player.getComponent(sp.Skeleton).setAnimation(0, "daiji1", true);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "1tui2", true);
      }
    }
  }, {
    key: "on_sheji",
    value: function on_sheji() {
      var _this45 = this;
      if (this.sheji_num <= 0) {
        if (this.huangdan1) {
          return void ("huangdan1" != this.player.getComponent(sp.Skeleton).animation && (this.huangdan1 = false));
        } else {
          return this.huangdan1 = true, this.player.getComponent(sp.Skeleton).setAnimation(0, "huangdan1", false), void this.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
            if ("huangdan1" === (e.animation.name ? e.animation.name : "")) {
              _this45.changedh();
              _this45.sheji_num = 2;
              _this45.huangdan1 = false;
            }
          });
        }
      }
      $2AudioManager.default.instance.playEffect($2KDefine.AudioName.sheji);
      this.player.getComponent(sp.Skeleton).setAnimation(0, "sheji1", false);
      this.player.getComponent(sp.Skeleton).setAnimation(1, "run2", true);
      this.sheji_num--;
      this.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
        "sheji1" === (e.animation.name ? e.animation.name : "") && _this45.changedh();
      });
      var e = cc.instantiate(this.zidanNode);
      e.parent = this.player;
      e.active = true;
      e.setPosition(this.player.x + 300, this.player.y + 600);
      e.getComponent(sp.Skeleton).setAnimation(0, "zidan", false);
      e.getComponent(sp.Skeleton).setCompleteListener(function () {
        e.removeFromParent();
      });
    }
  }, {
    key: "on_xiaza_end",
    value: function on_xiaza_end() {
      this.check_click(this.startClickTime);
    }
  }, {
    key: "check_click",
    value: function check_click(e) {
      var _this46 = this;
      var t = new Date().getTime();
      console.log(t - e);
      if (t - e > 600) {
        console.log("长按事件");
        this.player.getComponent(sp.Skeleton).setAnimation(0, "nieqiang1", false);
        var _e21 = this.player.getComponent(sp.Skeleton).getCurrent(0);
        _e21.timeScale = 1;
        _e21.animationStart = 1;
        this.player.getComponent(sp.Skeleton).setToSetupPose();
        this.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
          "nieqiang1" == e.animation.name && _this46.changedh();
        });
      } else if (t - e < 200) {
        this.clickTime++;
        setTimeout(function () {
          if (1 == _this46.clickTime) {
            console.log("单击事件");
            _this46.player.getComponent(sp.Skeleton).setAnimation(0, "lunqiang1", false);
            var _e22 = _this46.player.getComponent(sp.Skeleton).getCurrent(0);
            _e22.timeScale = 1;
            _e22.animationStart = 10 / 30;
            _this46.player.getComponent(sp.Skeleton).setToSetupPose();
            _this46.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
              "lunqiang1" == e.animation.name && _this46.changedh();
            });
          } else {
            2 == _this46.clickTime && console.log("双击事件");
          }
          _this46.clickTime = 0;
        }, 200);
      }
    }
  }, {
    key: "on_xiaza",
    value: function on_xiaza() {
      $2AudioManager.default.instance.playEffect($2KDefine.AudioName.lunqiang);
      this.startClickTime = new Date().getTime();
      this.player.getComponent(sp.Skeleton).setAnimation(0, "nieqiang1", false);
      var e = this.player.getComponent(sp.Skeleton).getCurrent(0);
      console.log(e.animationStart, e.animationEnd);
      e.animationStart = 0;
      e.animationEnd = 25 / 30;
      if ($2DataManager.default.instance.is_running) {
        this.player.getComponent(sp.Skeleton).setAnimation(1, "run2", true);
      } else {
        this.player.getComponent(sp.Skeleton).setAnimation(1, "1tui2", true);
      }
      this.player.getComponent(sp.Skeleton).setCompleteListener(function (e) {
        "nieqiang1" == e.animation.name && (e.timeScale = 0);
      });
    }
  }, {
    key: "on_shangtiao",
    value: function on_shangtiao() {
      var _this47 = this;
      if (this.player.getComponent($2Role1.default).flag != y.tiao) {
        this.player.getComponent($2Role1.default).flag = y.tiao;
        this.player.getComponent(sp.Skeleton).setAnimation(0, "tiao1", false);
        this.player.getComponent(sp.Skeleton).setAnimation(1, "tiao2", false);
        cc.tween(this.player).by(.3, {
          position: cc.v3(0, 200, 0)
        }, {
          easing: "easeOutCubic"
        }).by(.3, {
          position: cc.v3(0, -200, 0)
        }, {
          easing: "easeInCubic"
        }).call(function () {
          _this47.player.getComponent($2Role1.default).flag = y.tiao_end;
          _this47.changedh();
        }).start();
      }
    }
  }, {
    key: "updateSpine",
    value: function updateSpine(e, t) {
      var a = e.getCurrent(0);
      var n = a.animationEnd * t;
      a.animationStart = n;
      e.setToSetupPose();
    }
  }, {
    key: "stopAtFrame",
    value: function stopAtFrame(e) {
      var t = this.player.getComponent(sp.Skeleton).getCurrent(0);
      var a;
      (a = -1 === e ? t.animation.duration : e > 1 ? (e - 1) / 30 : 0) < 0 && (a = 0);
      a >= t.animation.duration && (a = t.animation.duration - .01);
      t.timeScale = 0;
      t.trackTime = a;
    }
  }, {
    key: "update",
    value: function update(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      this.distance.getComponent(cc.Label).string = "".concat(Math.floor($2DataManager.default.instance.distance), "米");
      if (this.joyStick.getComponent($2JoyStick1.default).dir.mag() < .5) {
        return;
      }
      this.joyStick.getComponent($2JoyStick1.default).dir.x;
      this.speed;
      this.joyStick.getComponent($2JoyStick1.default).dir.y;
      this.speed;
      var t = Math.atan2(this.joyStick.getComponent($2JoyStick1.default).dir.y, this.joyStick.getComponent($2JoyStick1.default).dir.x);
      this.degree = cc.misc.radiansToDegrees(t);
      if (this.degree > 90 && this.degree <= 180 || this.degree < -90 && this.degree >= -180) {
        this.player.scaleX = -.3;
        this.bgs.getComponent($2BgCtrl.default).set_dir(1);
      } else {
        this.player.scaleX = .3;
        this.bgs.getComponent($2BgCtrl.default).set_dir(-1);
      }
      this.player.x > cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.x < -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX && (this.player.x = -cc.winSize.width / 2 - this.player.width / 2 * this.player.scaleX);
      this.player.y > cc.winSize.height / 2 - this.player.height * this.player.scaleY && (this.player.y = cc.winSize.height / 2 - this.player.height * this.player.scaleY);
      this.player.y < -cc.winSize.height / 2 && (this.player.y = -cc.winSize.height / 2);
    }
  }]);
  return C;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_DfbwzhUI.prototype, "fuhuoView", undefined);
cc__decorate([ccp_property(cc.Node)], def_DfbwzhUI.prototype, "endView", undefined);
cc__decorate([ccp_property(cc.Node)], def_DfbwzhUI.prototype, "zidanNode", undefined);
def_DfbwzhUI = cc__decorate([ccp_ccclass], def_DfbwzhUI);
exports.default = def_DfbwzhUI;